import 'package:flutter/material.dart';

class GestureDetectorPage extends StatelessWidget {
  const GestureDetectorPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('GestureDetector 所有属性示例')),
      body: Center(
        child: GestureDetector(
          // 单击
          onTap: () => debugPrint('onTap: 单击'),
          // 单击结束（手指抬起）
          onTapUp: (details) => debugPrint('onTapUp: 手指抬起: ${details.globalPosition}'),
          // // 单击开始（手指按下）
          onTapDown: (details) => debugPrint('onTapDown: 手指按下: ${details.globalPosition}'),
          // // 单击取消（被系统打断，比如滑动）
          onTapCancel: () => debugPrint('onTapCancel'),

          // 双击
          onDoubleTap: () => debugPrint('onDoubleTap'),

          // 长按
          onLongPress: () => debugPrint('onLongPress'),
          onLongPressStart: (details) => debugPrint('onLongPressStart: ${details.globalPosition}'),
          onLongPressMoveUpdate: (details) => debugPrint('onLongPressMoveUpdate: ${details.offsetFromOrigin}'),
          onLongPressUp: () => debugPrint('onLongPressUp'),
          onLongPressEnd: (details) => debugPrint('onLongPressEnd: ${details.velocity}'),

          // 拖动（一次性的）
          onVerticalDragDown: (details) => debugPrint('onVerticalDragDown'),
          onVerticalDragStart: (details) => debugPrint('onVerticalDragStart'),
          onVerticalDragUpdate: (details) => debugPrint('onVerticalDragUpdate: ${details.primaryDelta}'),
          onVerticalDragEnd: (details) => debugPrint('onVerticalDragEnd: ${details.velocity}'),
          onVerticalDragCancel: () => debugPrint('onVerticalDragCancel'),
          //
          // onHorizontalDragDown: (details) => debugPrint('onHorizontalDragDown'),
          // onHorizontalDragStart: (details) => debugPrint('onHorizontalDragStart'),
          // onHorizontalDragUpdate: (details) => debugPrint('onHorizontalDragUpdate'),
          // onHorizontalDragEnd: (details) => debugPrint('onHorizontalDragEnd'),
          // onHorizontalDragCancel: () => debugPrint('onHorizontalDragCancel'),

          // 任意方向拖动（自由）
          // onPanDown: (details) => debugPrint('onPanDown'),
          // onPanStart: (details) => debugPrint('onPanStart'),
          // onPanUpdate: (details) => debugPrint('onPanUpdate'),
          // onPanEnd: (details) => debugPrint('onPanEnd'),
          // onPanCancel: () => debugPrint('onPanCancel'),

          // 缩放手势（两个手指）
          // onScaleStart: (details) => debugPrint('onScaleStart'),
          // onScaleUpdate: (details) => debugPrint('onScaleUpdate: scale=${details.scale}, focalPoint=${details.focalPoint}'),
          // onScaleEnd: (details) => debugPrint('onScaleEnd'),

          // 行为控制
          behavior: HitTestBehavior.opaque, // 默认是 deferToChild。opaque 可以放大响应区域

          // 自定义子组件
          child: Container(
            width: 200,
            height: 200,
            alignment: Alignment.center,
            color: Colors.blue.shade200,
            child: const Text('点击/长按/滑动试试', style: TextStyle(fontSize: 16)),
          ),
        ),
      ),
    );
  }
}
